﻿// Developer Express Code Central Example:
// Using DXDocking for WPF in accordance with Composite Application Guidelines
// 
// This example contains a DXDocking (http://devexpress.com/DXDocking) to Prism
// (http://www.codeplex.com/CompositeWPF) adapter that allows you to use the
// DXDocking for WPF in your composite applications.
// The sample for version
// v10.2.5 supports Prism 4
// 
// See Also:
// Prism: patterns & practices Composite
// Application Guidance for WPF and Silverlight site
// (http://compositewpf.codeplex.com/)
// 
// You can find sample updates and versions for different programming languages here:
// http://www.devexpress.com/example=E1926

namespace Abc.Desktop.Adapters 
{
    using DevExpress.Xpf.Docking;

    using Microsoft.Practices.Prism.Regions;

    public class LayoutPanelAdapter : RegionAdapterBase<LayoutPanel> 
    {
        public LayoutPanelAdapter(IRegionBehaviorFactory behaviorFactory) :
            base(behaviorFactory) 
        {
        }

        protected override IRegion CreateRegion() 
        {
            return new SingleActiveRegion();
        }

        protected override void Adapt(IRegion region, LayoutPanel regionTarget) 
        {
            region.Views.CollectionChanged += (d, e) =>
            {
                if (e.NewItems != null)
                {
                    regionTarget.Content = e.NewItems[0];
                }
            };
        }
    }
}
